
package com.example;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import java.io.FileOutputStream;

public class SaveBitmapActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon_3d);
        saveBitmap(bm, "icon_3d.png");
    }

    public void saveBitmap(Bitmap bm, String fileName) {
        try {
            String baseFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/DCIM/Camera/";
            String filePath = baseFolderPath + fileName;

            FileOutputStream stream = new FileOutputStream(filePath);
            bm.compress(CompressFormat.PNG, 100, stream);
            stream.flush();
            stream.close();
        } catch (Exception e) {
            Log.e("Could not save", e.toString());
        }
    }

}
